function K = rbf_kernel(X1, X2, sigma)
    % Compute the squared Euclidean distance between each pair of rows in X1 and X2
    sqdist = pdist2(X1, X2, 'euclidean').^2;
    
    % Compute the RBF kernel
    K = exp(-sqdist / (2 * sigma^2));
end